package com.hxjr.dialog;

import android.content.Context;

/****
 * 对话框工具类
 * 
 * @author hush
 * 
 */

public class DialogUtils
{
	private SweetAlertDialog dialog;

	private static DialogUtils dialogUtils;

	public static DialogUtils getInstance()
	{
		if (null == dialogUtils)
		{
			dialogUtils = new DialogUtils();
		}
		return dialogUtils;
	}

	/** 加载对话框 */
	public SweetAlertDialog createLoadingDialog(Context mContext, String title)
	{
		cleanLastDialog();
		dialog = new SweetAlertDialog(mContext, SweetAlertDialog.PROGRESS_TYPE)
				.setTitleText(title);
		return dialog;
	}

	public SweetAlertDialog createLoadingDialog(Context mContext, int title)
	{
		cleanLastDialog();
		dialog = new SweetAlertDialog(mContext, SweetAlertDialog.PROGRESS_TYPE)
				.setTitleText(mContext.getResources().getString(title));
		return dialog;
	}

	/** 普通对话框 (只有标题) */
	public SweetAlertDialog createNormDialog(Context mContext, String title)
	{
		cleanLastDialog();
		dialog = new SweetAlertDialog(mContext).setTitleText(title);
		return dialog;
	}

	public SweetAlertDialog createNormDialog(Context mContext, int title)
	{
		cleanLastDialog();
		dialog = new SweetAlertDialog(mContext).setTitleText(mContext
				.getResources().getString(title));
		return dialog;
	}

	/** 创建警告对话框 */
	public SweetAlertDialog createWarnDialog(Context mContext, String title)
	{
		cleanLastDialog();
		dialog = new SweetAlertDialog(mContext, SweetAlertDialog.WARNING_TYPE)
				.setTitleText(title).setConfirmText("确定");
		return dialog;
	}

	/** 创建选择对话框 */
	public SweetAlertDialog createChooseDialog(Context mContext, String title,
			String sureContent, String cancelContent)
	{
		cleanLastDialog();
		dialog = new SweetAlertDialog(mContext, SweetAlertDialog.WARNING_TYPE)
				.setTitleText(title).setCancelText(cancelContent)
				.setConfirmText(sureContent).showCancelButton(true);
		return dialog;
	}

	/** 创建成功对话框 */
	public SweetAlertDialog createSuccessDialog(Context mContext, String title,
			String sureContent)
	{
		cleanLastDialog();
		dialog = new SweetAlertDialog(mContext, SweetAlertDialog.SUCCESS_TYPE)
				.setTitleText(title).setContentText(sureContent);
		return dialog;
	}

	public void cleanLastDialog()
	{
		if (dialog != null && dialog.isShowing())
		{
			dialog.dismiss();
			dialog = null;
		}
	}

}
